﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration.ConfigurationManager

Partial Class IntranetMantenimientoEquipo
    Inherits System.Web.UI.Page

    Dim Equipo As New Equipo
    Dim Equi As New EquipoBE
    Dim cn As New SqlConnection(ConnectionStrings("cn").ConnectionString)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, btnAgregar.Click
        If Not Page.IsPostBack Then
            llenarComboMarca()
            llenarGridView()
        End If
    End Sub

    Sub llenarComboMarca()

        cboMarca.DataSource = Equipo.ListaMarca()
        cboMarca.DataTextField = "Name_marca"
        cboMarca.DataValueField = "cod_marca"
        cboMarca.DataBind()
    End Sub

    Sub llenarGridView()
        GridView1.DataSource = Equipo.Listado()
        GridView1.DataBind()
    End Sub

    Protected Sub GridView1_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        GridView1.DataSource = Equipo.Listado()
        GridView1.DataBind()

        UpDatos.Update()
    End Sub

    Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        GridView1.Columns.Item(2).Visible = False
    End Sub

    'Protected Sub btnAgregar_Click(ByVal sender As Object, ByVal e As System.EventArgs)

   




    'End Sub


    Protected Sub btnAgregar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
        Dim des As String = txtDescripcion.Text
        Dim cod_mar As String = CType(cboMarca.SelectedValue(), String)
        Dim tip_equi As String = txtTipo.Text
        Dim pre_equi As Decimal = txtPrecio.Text
        Dim imagen As String = "HOLA"

        Dim i As Integer = Equipo.InsertarEquipo(des.Trim.ToUpper, cod_mar, tip_equi.Trim.ToUpper, pre_equi, imagen.Trim.ToUpper)


        If i = 1 Then
            GridView1.DataSource = Equipo.Listado
            GridView1.DataBind()

            UpDatos.Update()

        Else
            MsgBox("Ocurrio un error comuniquese con el area de sistemas")

        End If

    End Sub
End Class
